<?php
/**
 * Created by PhpStorm.
 * User: hanbin
 * Date: 17/5/30
 * Time: 下午9:27
 */

namespace App\Http\Controllers\Zhihu;


use App\Logic\zhihu\ServiceLogic;
use Validator;
/**
 * 服务
 * Class ServiceController
 * @package App\Http\Controllers\Zhihu
 */
class ServiceController extends BaseController
{
    public function __construct()
    {
        $this->setToken(false);
        parent::__construct();
    }

    /**
     * 列表
     * @return array
     */
    public function getList()
    {
        return ServiceLogic::getList();
    }

    /**
     * 详情
     * @return array
     */
    public function detail()
    {
        $rmsg = file_get_contents("php://input");
        $resultcode = json_decode($rmsg, true);
        $rule = [
            'id' => 'required|int',
        ];
        $message = [
            'id.regex' => 'ID不能为空',
        ];
        $validator = Validator::make($resultcode, $rule, $message);
        $errors = $validator->errors()->all();
        //如果验证不通过
        if (!empty($errors) && !$validator->passes()) {
            return $this->error($errors[0], 206);
        }
        return ServiceLogic::detail($resultcode['id']);
    }

}